<include file="public/header"/>
<link href="__TMPL__/public/assets/plugins/Fileinput/css/fileinput.css" rel="stylesheet">
<link rel="stylesheet" href="__STATIC__/js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
<style>
    .form-required{color: red}
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                        <h5>到款录入</h5>
                    <div class="ibox-tools">
                        <!--<a href="{:url('Menu/index')}" class="btn btn-primary btn-xs">后台菜单</a>
                        <a href="#" class="btn btn-primary btn-xs active">添加菜单</a>
                        <a href="{:url('Menu/lists')}" class="btn btn-primary btn-xs">所有菜单</a>-->
                    </div>
                </div>
                <div class="ibox-content">

                    <form class="form-horizontal js-ajax-form" action="{:url('add')}" method="post">

                        <div class="form-group">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-2">
                                <a class="help-block m-b-none" id="" style="cursor: pointer;color: #F56A6F;">
                                    <i class="fa fa-info-circle"></i> 填写客户信息</a>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>客户姓名</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-name" name="cust[name]" required value="{$data.name ?? ''}">
                        </div>

                        <label class="col-sm-1 control-label"><span class="form-required">*</span>联系方式</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-phone" name="cust[phone]" required value="{$data.phone ?? ''}" onchange="getCustomerInfo()">
                        </div>


                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>性别</label>
                        <div class="col-md-3" style="padding: 0px">
                            <div class="radio i-checks">
                                <label>
                                    <input type="radio" value="1" name="cust[sex]"> <i></i> 男</label>
                                <input type="radio" value="0" name="cust[sex]"> <i></i> 女</label>
                            </div>
                        </div>

                        <label for="input-age" class="col-sm-1 control-label">年龄</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="input-age" name="cust[age]" required value="{$data.age ?? ''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">客户行业</label>
                        <div class="col-md-3">
                            <input class="form-control" id="input-hangye" name="cust[hangye]" value="{$data.hangye ?? ''}"/>
                        </div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>客户等级</label>
                        <div class="col-md-3">
                            <select name="cust[level]" id="level" class="form-control">
                                <option value="-1">--请选择客户等级--</option>
                                <option value="1">普通客户</option>
                                <option value="2">普通员工</option>
                                <option value="3">公司高管</option>
                                <option value="4">VIP</option>
                            </select>
                        </div>

                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">新老客户</label>
                        <div class="col-md-3" style="padding: 0px">
                            <div class="radio i-checks">
                                <label><input type="radio" value="1" name="cust[is_new]" > <i></i> 新客户</label>
                                <label><input type="radio" value="0" name="cust[is_new]"> <i></i> 老客户</label>

                            </div>
                        </div>
                        <label class="col-sm-1 control-label">客户来源</label>
                        <div class="col-md-3">
                            <div class="radio i-checks">
                                <label><input type="radio" value="1" name="cust[from]"> <i></i> 个人查找</label>
                                <label><input type="radio" value="2" name="cust[from]"> <i></i> 主动联系</label>
                                <label><input type="radio" value="3" name="cust[from]"> <i></i> 公司派单</label>
                            </div>
                        </div>
                    </div>
                        <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">是否会员</label>
                        <div class="col-md-1" style="padding: 0px">
                            <div class="radio i-checks">
                                <label><input type="radio" value="1" name="cust[is_vip]"> <i></i> 是</label>
                                <label><input type="radio" value="0" name="cust[is_vip]"> <i></i> 否</label>

                            </div>
                        </div>
                        <div style="display: none" id="vip_box">
                            <label class="col-sm-1 control-label">会员编号</label>
                            <div class="col-md-2">
                                <input type="text" class="form-control" id="input-vip-number" name="cust[vip_number]" required value="{$data.age ?? ''}">
                            </div>

                            <label class="col-sm-1 control-label">验证码</label>
                            <div class="col-md-2">
                                <div class="input-group">
                                    <input type="text" class="form-control">
                                    <span class="input-group-btn" >
                                        <button type="button" class="btn btn-primary">获取验证码</button>
                                </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>地址</label>
                        <div class="col-md-2">
                            <select name="cust[prov]" id="province" class="form-control" onchange="getRegion(this.value,1)" >
                                <option value="-1">请选择地址</option>
                                <volist name="province" id="vo">
                                    <option value="{$vo.code}">{$vo.name}</option>
                                </volist>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <select name="cust[city]" id="city" class="form-control" onchange="getRegion(this.value,2)">
                                <option value="-1">请选择地址</option>
                                <if condition="$Request.action eq 'privateupdate'">
                                    <volist name="city" id="vo">
                                        <option value="{$vo.code}">{$vo.name}</option>
                                    </volist>
                                </if>
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <select name="cust[area]"  class="form-control" id="area">
                                <option value="-1">请选择地址</option>
                                <if condition="$Request.action eq 'privateupdate'">
                                    <volist name="area" id="vo">
                                        <option value="{$vo.code}">{$vo.name}</option>
                                    </volist>
                                </if>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>详细地址</label>
                        <div class="col-md-7">
                            <input type="text" class="form-control" id="input-address" name="cust[address]" required value="{$data.address ?? ''}">
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <div class="col-sm-2">
                            <a class="help-block m-b-none" id="dianji_box" style="cursor: pointer;color: #F56A6F;"><i class="fa fa-info-circle"></i> 填写打款信息</a>
                        </div>
                    </div>
                    <div class="companyBox">
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-md-1"></div>
                            <label class="col-sm-1 control-label">打款金额</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" id="input-comp-name" name="comp[name]"  value="{$comp.name ?? ''}">
                            </div>
                            <label class="col-sm-1 control-label">打款时间</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control js-bootstrap-datetime" autocomplete="off" aria-required="true" data-autoclose="true" id="input-comp-phone" name="comp[phone]"  value="{$comp.phone ?? ''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-md-1"></div>
                            <label class="col-sm-1 control-label">打款银行名称</label>
                            <div class="col-md-7">
                                <select name="bank_id"  class="form-control" id="bank_id">
                                            <option value="">请选择银行名称</option>
                                </select>
                            </div>

                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-1"></div>
                            <label class="col-sm-1 control-label">打款备注</label>
                            <div class="col-md-7">
                                <textarea class="form-control" id="input-content" name="cust[content]">{$data.content ?? ''}</textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-1"></div>
                            <label class="col-sm-1 control-label">打款截图</label>
                            <div class="col-md-7">
                                <input id="fileone" type="file" class="file-loading">
                                <input type="hidden" id="picurl" placeholder="缩略图" name="order[picurl]" value="{$order.picurl ?? ''}">
                            </div>

                        </div>



                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-4">
                            <input type="hidden" name="comp_id" value="{$data.comp_id ?? ''}">
                            <button class="btn btn-primary" type="submit">保存并录入产品</button>
                            <button class="btn btn-warning">录入预存款</button>
                            <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);" >返回</button>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__TMPL__/public/assets/js/jquery.min.js?v=2.1.4"></script>
<script src="__TMPL__/public/assets/js/bootstrap.min.js?v=3.3.5"></script>
<script src="__TMPL__/public/assets/js/content.min.js?v=1.0.0"></script>
<script src="__TMPL__/public/assets/js/plugins/iCheck/icheck.min.js"></script>

<script src="__TMPL__/public/assets/plugins/Fileinput/js/fileinput.js"></script>
<script src="__STATIC__/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        fileinputOne("fileone","picurl");

        $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        /*$('#dianji_box').click(function(){
            $('.companyBox').slideToggle('slow');
            $('.companyBox').css('display','block');
        });*/

        $('#input-comp-phone').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd hh:ii:ss',
            todayBtn:'linked',
            weekStart: 1,
            todayHighlight:true,
            initialDate:new Date(),
        });

    });

    function getRegion(val,level) {
        var $city = $("#city");
        var $area = $("#area");
        if (level == '1') {
            $city.html('<option value="-1"> --请选择市-- </option>');
            $city.val('');
        }
        $area.html('<option value="-1"> --请选择区-- </option>');
        $area.val('');
        $.post('{:url("admin/common/getRegion")}', {pcode: val, level: level}, function (data) {
            var dataObj = eval("(" + data + ")");
            if (dataObj['code'] == 1) {
                if (level == '1') {
                    $.each(dataObj['list'], function (i, item) {
                        $city.append('<option value="' + item['code'] + '">' + item['name'] + '</option>');
                    });
                } else {
                    $.each(dataObj['list'], function (i, item) {
                        $area.append('<option value="' + item['code'] + '">' + item['name'] + '</option>');
                    });
                }
            }
        });
    }
    /*上传单张图片的方法*/
    function fileinputOne(fileid,field){
        var widths = arguments[2] ? arguments[2] : 'auto';//设置默认的图片宽度
        var heights = arguments[3] ? arguments[3] : '160px';//设置默认的图片高度
        //单图上传
        var $input = $("#"+fileid);
        var $picurl = $("#"+field);

        var $Preview =[];
        var $Config =[];
        if($picurl.val()!=''){
            $Preview =["<img class='kv-preview-data file-preview-image' style='width:"+widths+";height:"+heights+";' src='__ROOT__"+$picurl.val()+"'>"];
            $Config =[{key: 1}];
        }
        $input.fileinput({
            uploadUrl: "{:url('admin/common/upload')}",
            deleteUrl: "{:url('admin/common/updel')}",
            autoReplace: true,
            overwriteInitial: true,
            showUploadedThumbs: false,
            maxFileCount: 1,
            initialPreview: $Preview,
            initialPreviewConfig: $Config,
            layoutTemplates: {actionDelete: ''},
        }).on("filebatchselected", function(event, files) {
            $input.fileinput("upload");//选择后自动上传
        }).on('fileuploaded', function(event, data,previewId,index) {
            //alert(JSON.stringify(data));
            var dataObj=eval("("+data.response+")");
            if(dataObj['code']==0)
            {
                $picurl.val(dataObj['img']);
            }
            else{
                swal("出错了", "上传失败,请刷新再试", "error");
            }
        }).on("filecleared", function(event, files) {
            $picurl.val('');
        });

    }
    /*获取用户信息*/
    function getCustomerInfo()
    {
       var phone =  $('#input-phone').val();
       var name  =  $('#input-name').val();

       $.post('{:url("admin/business/getCustomerInfo")}',{phone:phone,name:name},function (data) {
           var city  = -1;
           var area = -1;
           /*状态码==1 就说明该用户存在*/
           if (data.code == 1){
               var obj = data.data;
               $('#input-address').val(obj.address);
               $('#input-name').val(obj.name);
               $('#input-age').val(obj.age);
               $('#input-hangye').val(obj.hangye);
               $("[name='cust[level]']").find("[value='"+obj.level+"']").attr("selected", true);
               $("[name='cust[prov]']").find("[value='"+obj.province+"']").attr("selected", true);
               $("[name='cust[is_new]'][value='"+obj.is_New+"']").attr("checked", true);
               $("[name='cust[from]'][value='"+obj.from+"']").attr("checked", true);
               $("[name='cust[sex]'][value='"+obj.sex+"']").prop("checked", 'checked');
               $("[name='cust[is_vip]'][value='"+obj.is_vip+"']").prop("checked", 'checked');
                if(obj.is_vip == 1){
                    $('#input-vip-number').val(obj.vip_number);
                    $('#vip_box').css('display','block');
                }
               $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

               getRegion(obj.province,1);
               getRegion(obj.city,2);
               selectData(1,obj.city);
               city = obj.city;
               area = obj.area;
           }
           selectData(1,city);
           selectData(2,area);
       });
    }
    //根据ajax返回的数据选中地址的方法
    function selectData(lavel,id){
        if(lavel == 1){
            $("[name='cust[city]']").find("[value='"+id+"']").attr("selected", true);
        }else{
            $("[name='cust[area]']").find("[value='"+id+"']").attr("selected", true);
        }
    }

</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
</body>
</html>